// import zhCN from "./lang/zh"
// import en from "./lang/en"
// import ruRU from "./lang/ru"
// import enLocale from 'element-ui/lib/locale/lang/en'
// import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
// import ruRULocale from 'element-ui/lib/locale/lang/ru-RU'


const files = require.context("@/i18n/lang", false, /\.js$/)
const element_lang = require.context("element-ui/lib/locale/lang", false, /.+(?!\.js)$/)

const messages = {}

files.keys().forEach((item) => {
  const file = files(item)
  const fileName = _.replace(_.replace(item, /\.js$/, ''), /^\.\//, '')
  const fileContent = file.default
  messages[fileName] = fileContent

  const element_path = _.find(element_lang.keys(), it => _.replace(it, /^\.\//, '').substr(0, 2) == fileName)
  if (element_path) {
    messages[fileName] = Object.assign({}, messages[fileName], element_lang(element_path).default)
  }
  if (process.env.NODE_ENV != 'production') {
    var axios = require('axios');
    async function queryDate() {
      // await的作用就是将异步函数变成同步操作
      return await axios.get('/i18n/i18n_server/I18nRpc/exportJson.json?appCode=front,java_enum&lan=' + fileName)
    }
    let testData = queryDate()
    testData.then(res => {
      if (res.data.code == 0) {
        messages[fileName] = Object.assign({}, messages[fileName], res.data.data)
      }
    })

  }

})

const i18n_main = {
  "locale": 'zh',
  "messages": messages,
  silentTranslationWarn: true // 去掉警告
}

export default i18n_main
